package com.haoniu.web.controller.module;

import com.haoniu.framework.util.ShiroUtils;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.ui.ModelMap;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import com.haoniu.common.annotation.Log;
import com.haoniu.common.enums.BusinessType;
import com.haoniu.module.domain.database.RedPacketLog;
import com.haoniu.module.service.RedPacketLogService;
import com.haoniu.web.core.base.BaseController;
import com.haoniu.framework.web.page.TableDataInfo;
import com.haoniu.common.base.AjaxResult;

import java.util.List;
/**
 * 红包流水记录 信息操作处理
 *
 * @author houyijun
 * @date 2019-02-18
 */
@Controller
@RequestMapping("/module/redPacketLog")
public class RedPacketLogController extends BaseController
{
    private String prefix = "module/redPacketLog";

	@Autowired
	private RedPacketLogService redPacketLogService;

	@RequiresPermissions("module:redPacketLog:view")
	@GetMapping()
	public String redPacketLog()
	{
	    return prefix + "/redPacketLog";
	}

	/**
	 * 查询红包流水记录列表
	 */
	@RequiresPermissions("module:redPacketLog:list")
	@PostMapping("/list")
	@ResponseBody
	public TableDataInfo list(RedPacketLog redPacketLog) {
		startPage();
        List<RedPacketLog> list = redPacketLogService.selectRedPacketLogList(redPacketLog);
		return getDataTable(list);
	}

	/**
	 * 新增红包流水记录
	 */
	@GetMapping("/add")
	public String add() {
	    return prefix + "/add";
	}

	/**
	 * 新增保存红包流水记录
	 */
	@RequiresPermissions("module:redPacketLog:add")
	@Log(title = "红包流水记录", businessType = BusinessType.INSERT)
	@PostMapping("/add")
	@ResponseBody
	public AjaxResult addSave(RedPacketLog redPacketLog) {
        redPacketLog.setCreateBy(ShiroUtils.getLoginName());
		return toAjax(redPacketLogService.insertRedPacketLog(redPacketLog));
	}

	/**
	 * 修改红包流水记录
	 */
	@GetMapping("/edit/{id}")
	public String edit(@PathVariable("id") Integer id, ModelMap mmap) {
		RedPacketLog redPacketLog = redPacketLogService.selectRedPacketLogById(id);
		mmap.put("redPacketLog", redPacketLog);
	    return prefix + "/edit";
	}

	/**
	 * 修改保存红包流水记录
	 */
	@RequiresPermissions("module:redPacketLog:edit")
	@Log(title = "红包流水记录", businessType = BusinessType.UPDATE)
	@PostMapping("/edit")
	@ResponseBody
	public AjaxResult editSave(RedPacketLog redPacketLog) {
        redPacketLog.setUpdateBy(ShiroUtils.getLoginName());
		return toAjax(redPacketLogService.updateRedPacketLog(redPacketLog));
	}

	/**
	 * 删除红包流水记录
	 */
	@RequiresPermissions("module:redPacketLog:remove")
	@Log(title = "红包流水记录", businessType = BusinessType.DELETE)
	@PostMapping( "/remove")
	@ResponseBody
	public AjaxResult remove(String ids) {
		return toAjax(redPacketLogService.deleteRedPacketLogByIds(ids));
	}

}
